package module.main.view.mainInterface.playerresourcepanel
{

	
	import code.ui.SimpleToolTips;
	import code.utils.MaterialUtil;
	
	import com.darwin.darwinUI.containers.ContainerBase;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.general.TextFieldFactory;
	import com.darwin.darwinUI.manager.ToolTipManager;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import main.App;
	
	import module.main.view.MainView;
	import module.main.view.ResourceConst;
	import module.main.view.mainInterface.PlayGradePlane;

	public class GoldItem extends ContainerBase
	{
		private var _goldBackground:Sprite;
		private var _goldIcon:Sprite;
		private var _goldBuyIcon:Sprite;
		private var _goldNumTxt:Label;
		private var uicommand:UIComponent;
		public function GoldItem()
		{
			uicommand = new UIComponent();
			_goldBackground = MaterialUtil.getPreloadMaterial("main",ResourceConst.RESOURCEINFO_GOLD_BACKGROUND) as Sprite;
			_goldIcon = MaterialUtil.getPreloadMaterial("main",ResourceConst.RESOURCEINFO_GOLD_ICON) as Sprite;
			_goldBuyIcon = MaterialUtil.getPreloadMaterial("main",ResourceConst.RESOURCEINFO_BUYGOLD_ICON) as Sprite;
			if(MainView.getInstance().playerObj)
			{
				_goldNumTxt.text = MainView.getInstance().playerObj.gold.toString();
			}
			else
			{
				_goldNumTxt = TextFieldFactory.getInstance().getLabel("mainInterface_resource_number");
				_goldNumTxt.text = "99999";
			}
			
			this.width = _goldBackground.width;
			this.height = _goldBackground.height;
			uicommand.width = _goldBackground.width;
			uicommand.height = _goldBackground.height;
			addItem(uicommand);
			_goldIcon.addEventListener(MouseEvent.MOUSE_MOVE,mousemoveHandler)
			init();
		}

		private function mousemoveHandler(e:MouseEvent):void
		{
			if(MainView.getInstance().playerObj)
			{
				UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"当前金币数量<br>" + MainView.getInstance().playerObj.gold,ToolTipManager.DOWN);
			}
		}
		public function set goldNumTxt(value:Label):void
		{
			_goldNumTxt = value;
		}

		public function get goldNumTxt():Label
		{
			return _goldNumTxt;
		}

		private function init():void
		{
			putgoldBackground();
			putgoldIcon();
			putgoldBuyIcon();
		}
		private function putgoldBackground():void
		{
			_goldBackground.x = 0;
			_goldBackground.y = 0;
			uicommand.addChild(_goldBackground);
		}
		private function putgoldIcon():void
		{
			_goldIcon.x = 10;
			_goldIcon.y = 10;
			_goldNumTxt.x = _goldIcon.x + 25;
			_goldNumTxt.y = _goldIcon.y;
			uicommand.addChild(_goldIcon);
			uicommand.addChild(_goldNumTxt);
		}
		private function putgoldBuyIcon():void
		{
			_goldBuyIcon.x = _goldBackground.width - _goldBuyIcon.width - 9;
			_goldBuyIcon.y = _goldIcon.y;
			uicommand.addChild(_goldBuyIcon);
		}
	}
}